package com.around.sprintboot_init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.converter.json.GsonBuilderUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    // 方式1
    @Value("${name}")
    private String name;

    @Value("${person.name}")
    private String name1;

    @Value("${person.age}")
    private String age;

    @Value("${address[0]}")
    private String address;

    // 方式2
    @Autowired
    private Environment env;

    // 方式3
    @Autowired
    Person person;

    @GetMapping("/hello/")
    public String hello() {
        System.out.println(name);
        System.out.println(name1);
        System.out.println(age);
        System.out.println(address);
        System.out.println("-------------------------------");
        System.out.println(env.getProperty("person.name"));
        System.out.println(env.getProperty("person.age"));
        System.out.println(env.getProperty("address[0]"));
        System.out.println("-------------------------------");
        System.out.println(person);
        String[] address1 = person.getAddress();
        for( String add: address1){
            System.out.println(add);
        }

        return "hello world";
    }
}
